package day9;

public class UnusualAdd {
    //二进制位相异或的结果，是两个数对应位相加的结果，不考虑进位
    //二进制位与后左移一位的结果，是两个数相加进位后的结果（只考虑进位)
    public int addAB(int A, int B) {
        // write code here
        if(B == 0) {
            return A;
        }
        int sum = 0;
        int carray = 0;
        while(B != 0) {
            sum = A^B;
            carray = (A&B) << 1;
            A = sum;
            B = carray; 
        }
        return sum;
    }
}